﻿<%@ Control Language="C#" Inherits="VioletDevelopmentLaboratory.Net.Web.UserControlBase" %>
<%@ Import Namespace="System.Net.Mail" %>

<script runat="server">
	protected void SendButton_Click(object sender, EventArgs e)
	{
		MailMessage message = new MailMessage();
		message.From = new MailAddress(FromTextBox.Text);
		message.Subject = SubjectTextBox.Text;
		message.Body = BodyTextBox.Text;
		message.IsBodyHtml = IsBodyHtmlCheckBox.Checked;

		foreach (string email in ToTextBox.Text.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries))
		{
			message.To.Add(email);
		}
		
		foreach (string email in BccTextBox.Text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
		{
			message.Bcc.Add(email);
		}

		foreach (string email in CCTextBox.Text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
		{
			message.CC.Add(email);
		}

		message.DeliveryNotificationOptions = (DeliveryNotificationOptions)Enum.Parse(typeof(DeliveryNotificationOptions), DeliveryNotificationOptionsRadioButtonList.SelectedValue);

		message.Priority = (MailPriority)Enum.Parse(typeof(MailPriority), PriorityRadioButtonList.SelectedValue);

		SmtpClient smtp = new SmtpClient();
		smtp.Send(message);
	}
</script>

<fieldset style="padding : 15px;">
	<legend>Send Email</legend>
	<p>
		From<br />
		<asp:TextBox ID="FromTextBox" runat="server" Columns="60"></asp:TextBox>
		<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
			ControlToValidate="FromTextBox" Display="Dynamic" 
			ErrorMessage="*"></asp:RequiredFieldValidator>
		<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
			ErrorMessage="* Invalid Email Address" Display="Dynamic" 
			ControlToValidate="FromTextBox" 
			ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
	</p>
	<p>
		To(seperate ;)<br />
		<asp:TextBox ID="ToTextBox" runat="server" Columns="60"></asp:TextBox>
		<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
			ControlToValidate="ToTextBox" Display="Dynamic" 
			ErrorMessage="* Required"></asp:RequiredFieldValidator>
	</p>
	<p>
		Bcc(seperate ;)<br />
		<asp:TextBox ID="BccTextBox" runat="server" Columns="60"></asp:TextBox>
	</p>
	<p>
		CC(seperate ;)<br />
		<asp:TextBox ID="CCTextBox" runat="server" Columns="60"></asp:TextBox>
	</p>
	<p>
		DeliveryNotification<br />
		<asp:RadioButtonList ID="DeliveryNotificationOptionsRadioButtonList" runat="server" RepeatDirection="Horizontal">
			<asp:ListItem>Delay</asp:ListItem>
			<asp:ListItem>Never</asp:ListItem>
			<asp:ListItem Selected="True">None</asp:ListItem>
			<asp:ListItem>OnFailure</asp:ListItem>
			<asp:ListItem>OnSuccess</asp:ListItem>
		</asp:RadioButtonList>
	</p>
	<p>
		Priority<br />
		<asp:RadioButtonList ID="PriorityRadioButtonList" runat="server" 	RepeatDirection="Horizontal">
			<asp:ListItem>High</asp:ListItem>
			<asp:ListItem Selected="True">Normal</asp:ListItem>
			<asp:ListItem>Low</asp:ListItem>
		</asp:RadioButtonList>
	</p>
	<p>
		Subject<br />
		<asp:TextBox ID="SubjectTextBox" runat="server" Columns="60"></asp:TextBox>
		<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
			ControlToValidate="SubjectTextBox" Display="Dynamic" ErrorMessage="* Required"></asp:RequiredFieldValidator>
	</p>
	<p>
		Body<br />
		<asp:TextBox ID="BodyTextBox" runat="server" TextMode="MultiLine" Rows="10" Columns="60"></asp:TextBox><br />
		
		<asp:CheckBox ID="IsBodyHtmlCheckBox" runat="server" Text="Html" />
		
	</p>
	<p>
		<asp:Button ID="SendButton" runat="server" Text="Send" onclick="SendButton_Click" />
	</p>
</fieldset>